package com.mxpio.erp.common.util;

import com.mxpio.erp.common.enums.BizExceptionEnums;
import com.mxpio.erp.common.exception.BizException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

public class AssertUtil {

    public static void notNull(Object source, BizExceptionEnums enums) {

        if (Objects.isNull(source)) {
            throw new BizException(enums);
        }
    }

    public static void notNull(Object source, BizExceptionEnums enums, String message) {

        if (Objects.isNull(source)) {
            throw new BizException(enums, message);
        }
    }

    public static void notEmpty(List<?> source, BizExceptionEnums enums, String message) {

        if (CollectionUtils.isEmpty(source)) {
            throw new BizException(enums, message);
        }
    }

    public static void notEmpty(String source, BizExceptionEnums enums, String message) {

        if (StringUtils.isEmpty(source)) {
            throw new BizException(enums, message);
        }
    }

    public static void isTrue(Boolean flag, BizExceptionEnums enums,String message) {

        if (!flag) {
            throw new BizException(enums,message);
        }

    }

    public static void isTrue(Boolean flag, BizExceptionEnums enums) {

        if (!flag) {
            throw new BizException(enums);
        }

    }

    public static void isFalse(Boolean flag, BizExceptionEnums enums) {

        if (flag) {
            throw new BizException(enums);
        }

    }

    public static void isFalse(Boolean flag, BizExceptionEnums enums,String message) {

        if (flag) {
            throw new BizException(enums,message);
        }

    }

}
